<include file="Public/head"/>
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<script src="http://img1.isou365.cn/paimai/yunying/js/city.js" type="text/javascript"></script>
<style>
    .shop_details ul li span .menHover {  background: #20ab4f;  color: #fff;  }
    .menDao a {background: #cecece; color: #303030; padding: 0 10px;  text-align: center;  height: 24px;  line-height: 24px;  cursor: pointer;  }

    .account{width:90%;float: left;}
    .accountCurrent{background-color: #33CCFF;color:#fff9f9;}
    .account ul{padding: 0px;}
    .account ul li{width: 40%;margin:0;padding:10px 0;border-radius: 5px;border:1px solid #E4E4E4;float: left;}
    .account ul>li:not(:first-child){margin-left: 4%;}
    .account ul li:hover{cursor:pointer;}
    .account ul li div{width: 100%;clear: both;}
    .account ul li span{height:25px;line-height:25px;display: block;width: auto;}
    .account ul li .span_right{text-align: right;width: 28%;}
</style>
<include file="Public/common_header"/>
<div class="mian">
    <include file="Public/sidebar" menu="zsgl.zscl"/>
    <div class="mianR">
        <div class="listBox">
            <h3 class="cha">车辆处理详情</h3>
            <div class="car_info">
                <div class="car_no"><span style="font-size:14px;">车辆编号：<b>{$detail.sno}</b></span></div>
                <table border="1" width="100%">
                    <tbody>
                    <tr>
                        <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>车主信息</span></td>
                    </tr>
                    <tr>
                        <td width="11%" style="color:#898b8a;">车主类型</td>
                        <td width="39%">{$detail.owner_type_name}</td>
                        <if condition="$detail.owner_type eq 1">
                            <td width="11%" style="color:#898b8a;">车主姓名</td>
                            <td width="39%">{$detail.seller_name}</td>
                            <else />
                            <td width="11%" style="color:#898b8a;">公司名称</td>
                            <td width="39%">{$detail.seller_name}</td>
                        </if>
                    </tr>
                    <tr>
                        <if condition="$detail.owner_type eq 1">
                            <td width="11%" style="color:#898b8a;">联系电话</td>
                            <td colspan="3">{$detail.seller_phone}</td>
                            <else />
                            <td width="11%" style="color:#898b8a;">联系人姓名</td>
                            <td width="39%">{$detail.contact_person}</td>
                            <td width="11%" style="color:#898b8a;">联系电话</td>
                            <td width="39%">{$detail.seller_phone}</td>
                        </if>
                    </tr>
                    </tbody>
                </table>

                <table border="1" width="100%" style="margin-top:10px;">
                    <tbody>
                    <tr>
                        <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>评估师信息</span></td>
                    </tr>
                    <tr>
                        <td width="11%" style="color:#898b8a;">评估师姓名</td>
                        <td width="39%">{$detail.checker_name}</td>
                        <td width="11%" style="color:#898b8a;">评估师电话</td>
                        <td width="39%">{$detail.checker_phone}</td>
                    </tr>
                    </tbody>
                </table>

                <table border="1" width="100%" style="margin-top:10px;">
                    <tbody>
                    <tr>
                        <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                            <span>车辆信息</span>
                            <span style="float:right;padding-right: 10%;">
                                <a style="color:#20ab4f;font-weight:bolder;text-decoration: underline" href="{:U('Car/report',['car_id'=>$detail['car_id']])}" target="_blank">检测报告</a>
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td width="11%" style="color:#898b8a;">车型</td>
                        <td width="39%">{$detail.model}</td>
                        <td width="11%" style="color:#898b8a;">排放标准</td>
                        <td width="39%">{$detail.emission}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">初登日期</td>
                        <td>{$detail.first_reg_date}</td>
                        <td style="color:#898b8a;">颜色</td>
                        <td>{$detail.car_color}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">表显里程</td>
                        <td>{$detail.pointer_mileage}万公里</td>
                        <td style="color:#898b8a;">车况级别</td>
                        <td>{$detail.composite_state}{$detail.accident_level}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">车辆注册地</td>
                        <td>{$detail.first_reg_city}</td>
                        <td style="color:#898b8a;">车架号</td>
                        <td>{$detail.vin}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">过户限制</td>
                        <td>{$detail.transfer_limit_str}</td>
                        <td style="color:#898b8a;">车牌号</td>
                        <td>{$detail.plate_prefix}{$detail.plate_suffix}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">渠道来源</td>
                        <td>
                            <if condition="$detail.comefrom neq ''">
                                <?php if(empty($detail['comefrom_url'])):?>
                                {$detail.comefrom}
                                <?php else: ?>
                                <a href="{$detail.comefrom_url}" target="_blank" rel="noreferrer">{$detail.comefrom}</a>
                                <?php endif;?>
                                <else/>
                                未知
                            </if>
                        </td>
                        <td style="color:#898b8a;">所在地</td>
                        <td>{$detail.location_area}</td>
                    </tr>
                    </tbody>
                </table>

                <table border="1" width="100%" style="margin-top:10px;">
                    <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>自收信息</span></td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">成交时间</td>
                            <td width="39%">
                                {$detail['self_success_trade_time']}
                            </td>
                            <td width="11%" style="color:#898b8a;">成交价格</td>
                            <td width="39%">{:format_money($detail['self_receive_price'])}元</td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">自收保留价</td>
                            <td width="39%">{:format_money($detail['reserve_price'])}元</td>
                            <td width="11%" style="color:#898b8a;">自收人</td>
                            <td width="39%">{$detail['self_dealer_name']}</td>
                        </tr>
                    </tbody>
                </table>

                <if condition="$detail.pay_status gt 0">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                                <!--<span>
                                    付款信息（{$detail.pay_status_name}<if condition="$detail.pay_status_type eq 21"> 100%）<elseif condition="$detail.pay_status_type eq 22"/> 50%）<elseif condition="$detail.pay_status_type eq 23"/> 0%）<else />）</if>
                                </span>-->
                                付款信息({$detail.pay_status_name})
                            </td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">付款人</td>
                            <td width="39%">
                                {$detail.pay_man}
                            </td>
                            <td width="11%" style="color:#898b8a;">付款时间</td>
                            <td width="39%">
                                {$detail.pay_time}
                            </td>
                        </tr>
                        <!--<tr>
                            <td width="11%" style="color:#898b8a;">付款人</td>
                            <td width="39%">
                                <if condition="$detail.pay_status eq 2">
                                    {$detail.pay_man}
                                    <else />
                                    &#45;&#45;
                                </if>
                            </td>
                            <td width="11%" style="color:#898b8a;">付款时间</td>
                            <td width="39%">
                                <if condition="$detail.pay_status eq 2">
                                    {$detail.pay_time}
                                    <else />
                                    &#45;&#45;
                                </if>
                            </td>
                        </tr>-->
                        </tbody>
                    </table>
                </if>

                <if condition="$detail.car_source eq 1">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                                <span>复检信息</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">手续复检人</td>
                            <td width="39%">{$detail.procedure_checker}</td>
                            <td width="11%" style="color:#898b8a;">车况复检人</td>
                            <td width="39%">{$detail.condition_checker}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">复检时间</td>
                            <td colspan="4">{$detail.recheck_time}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">车况描述</td>
                            <td colspan="4">{$detail.recheck_remark}</td>
                        </tr>
                        </tbody>
                    </table>
                </if>

                <if condition="$detail.self_type eq 3 AND $detail.compensate_type eq 1">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>争议信息（我方违约）</span></td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">仲裁员</td>
                            <td width="39%">{$detail.emp_name}</td>
                            <td width="11%" style="color:#898b8a;">仲裁时间</td>
                            <td width="39%">{$detail.createtime}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">补偿车商金额</td>
                            <td colspan="3">{$detail.cut_down_price}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">备注</td>
                            <td colspan="3">{$detail.issue_remark}</td>
                        </tr>
                        </tbody>
                    </table>
                </if>

                <if condition="$detail.self_type eq 3 AND $detail.compensate_type eq 2">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>争议信息（车商违约）</span></td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">仲裁员</td>
                            <td width="39%">{$detail.emp_name}</td>
                            <td width="11%" style="color:#898b8a;">仲裁时间</td>
                            <td width="39%">{$detail.createtime}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">扣除车商金额</td>
                            <td colspan="3">{$detail.cut_down_price}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">备注</td>
                            <td colspan="3">{$detail.issue_remark}</td>
                        </tr>
                        </tbody>
                    </table>
                </if>


                <if condition="$detail.self_type eq 2 AND $detail.compensate_type eq 3">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>备注信息</span></td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">平台确认备注</td>
                            <td width="89%">
                                {$detail.platform_confirm_remark}
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </if>
            </div>
        </div>

        <h3 class="yonghu">请选择车辆处理结果</h3>
        <div class="yuyue">
            <ul>
                <li class="yuCurrent" >重拍</li>
                <li>退车</li>
                <li>其他渠道成交</li>
            </ul>
        </div>
        <div class="listBox">
            <div class="yuList">
                <div class="shop_details">
                    <ul>
                        <li>
                            <span>保留价</span>
                            <em><input id="reserve_price" type="text" name="reserve_price" value="{$detail.reserve_price}" placeholder="请输入保留价" /> 元</em>
                        </li>
                        <li>
                            <span>报告处理方式</span>
                            <span class="menDao" id="treatment">
                                    <a href="javascript:void(0);" onclick="$('#is_re_check').val(0);" class="menHover">原报告</a>
                                    <a href="javascript:void(0);" onclick="$('#is_re_check').val(1);" >重新检测</a>
                                </span>
                            <input type="hidden" id="is_re_check" name="is_re_check"  value="0"/>
                        </li>
                        <div class="rechck_status" style="display: none">
                            <li>
                                <span>预约时间</span>
                                <input type="text" id="reserve_time" name="reserve_time" class="xiaci" value="" placeholder="请选择预约时间" readonly="true">
                            </li>
                            <li>
                                <span>预约门店</span>
                                <div class="detailed" style="display: block;">
                                    <select id="reserve_store" name="reserve_store" style="width:150px;">
                                        <option value="0">请选择门店</option>
                                        <?php foreach($stores as $key=>$vs):?>
                                        <option value="{$key}">{$vs}</option>
                                        <?php endforeach;?>
                                    </select>
                                </div>
                            </li>
                        </div>
                        <li>
                            <span>备注</span>
                            <textarea id="cp_remark" class="remarks_text"></textarea>
                        </li>
                    </ul>
                </div>
                <div class="yongBtn">
                    <input type="button" data-id="1" value="确定" class="queding self_reauction">
                    <input type="button" onclick="history.back();" class="quxiao" value="返回">
                </div>
            </div>
            <div class="yuList" style="display: none;">
                <div class="shop_details">
                    <!--<ul>
                        <li>
                            <span>退车原因</span>
                            <span class='menDao' style="width:200px;">
                                <a href="javascript:void(0);" onclick="$('#back_method').val(2);"  class="menHover">车主原因</a>
                                <a href="javascript:void(0);" onclick="$('#back_method').val(1);" >检测失误</a>
                            </span>
                            <input type="hidden" id="back_method" name="back_method"  value="2"/>
                        </li>

                        <li>
                            <span id='kouchu'>扣除金额</span>
                            <span id='buchang'  style='display:none;'>补偿金额</span>
                            <em><input id="compensate" type="text" name="compensate" value="" placeholder="" /> 元</em>
                        </li>
                        <if condition="$detail.car_source eq 1">
                            <li id='dakuan' style="display: none;">
                                <span>打款账号</span>
                                <ul>
                                    <li class="clearfix">
                                        <input type="hidden" name="account_id" id="account_id" value="">
                                        <input type="hidden" name="bank_name" id="bank_name" value="">
                                        <input type="hidden" name="card_no" id="card_no" value="">
                                        <input type="hidden" name="account_name" id="account_name" value="">
                                        <div class="account">
                                            <ul>
                                                <volist name="fours_bank_account" id="fba" key="k">
                                                    <li class="clearfix" data-id="{$fba.id}" data-bank-name="{$fba.bank_name}" data-card-no="{$fba.card_no}" data-account-name="{$fba.account_name}">
                                                        <if condition="$fours_bank_account_total gt 1">
                                                            <div>
                                                                <span class="span_right">打款帐号{$k}&nbsp;&nbsp;</span>
                                                            </div>
                                                        </if>
                                                        <div>
                                                            <span class="span_right">开户银行：</span>
                                                            <span style="width: auto;">{$fba.bank_name}</span>
                                                        </div>
                                                        <div>
                                                            <span class="span_right">银行账号：</span>
                                                            <span style="width: auto;">{$fba.card_no}</span>
                                                        </div>
                                                        <div>
                                                            <span class="span_right">账户名：</span>
                                                            <span style="width: auto;">{$fba.account_name}</span>
                                                        </div>
                                                    </li>
                                                </volist>
                                            </ul>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                        </if>
                        <li>
                            <span>备注</span>
                            <textarea id="refund_remark" class="remarks_text"></textarea>
                        </li>
                    </ul>--> <!--旧的退车流程-->


                    <ul>
                        <li>
                            <span>退车原因</span>
                            <span class='menDao1' id="treatment1">
                                    <a href="javascript:void(0);" onclick="$('#payment_reason').val(1);" class="menHover">平台失误</a>
                                    <a href="javascript:void(0);" onclick="$('#payment_reason').val(2);">卖方违约</a>
                                    <a href="javascript:void(0);" onclick="$('#payment_reason').val(3);">平退</a>
                                </span>
                            <input type="hidden" id="payment_reason" name="payment_reason" value="1"/>
                        </li>
                        <li>
                            <div class="reasons">
                                <div class="reasons-list">
                                    <table>
                                        <thead>
                                        <tr><td width="20%">类型</td><td width="20%">收付类型</td><td width="20%">金额</td><td width="40%">备注</td></tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>车款</td>
                                            <td>收款</td>
                                            <td>
                                                <notempty name="first_payment_data">
                                                    <i class="receivables-money">{$first_payment_data.amount}</i>元
                                                    <else/>
                                                    <i class="receivables-money">0</i>元
                                                </notempty>
                                            </td>
                                            <td>
                                                <textarea name="remark_amount_of_car"></textarea>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>赔付车主</td>
                                            <td>付款</td>
                                            <td>
                                                    <span>
                                                        <input type="text" value="" name="payment_amount" class="paragraph"><label>元</label>
                                                    </span>
                                            </td>
                                            <td>
                                                <textarea name="remark_payment"></textarea>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    <div class="receivable-money"><i>应收车款</i>：<span></span>元</div>
                                    <if condition="$detail.car_source eq 1">
                                        <div class="playMoney clearfix">
                                            <span>打款账号</span>
                                            <input type="hidden" name="account_id" id="account_id_new" value="">
                                            <input type="hidden" name="bank_name" id="bank_name_new" value="">
                                            <input type="hidden" name="card_no" id="card_no_new" value="">
                                            <input type="hidden" name="account_name" id="account_name_new" value="">

                                            <volist name="fours_bank_account" id="fba" key="k">
                                                <table>
                                                    <tbody>
                                                    <tr>
                                                        <td width="25%" class="play-number">打款帐号{$k}</td>
                                                        <td class="account_id" style="display: none">{$fba.id}</td>
                                                    </tr>
                                                    <tr><td width="25%" class="play-number">开户银行：</td><td class="bank_name">{$fba.bank_name}</td></tr>
                                                    <tr><td width="25%" class="play-number">银行账号：</td><td class="card_no">{$fba.card_no}</td></tr>
                                                    <tr><td width="25%" class="play-number">账户名：</td><td class="account_name">{$fba.account_name}</td></tr>
                                                    </tbody>
                                                </table>
                                            </volist>
                                        </div>
                                    </if>
                                </div>

                                <div class="reasons-list" style="display: none;">
                                    <table>
                                        <thead>
                                        <tr><td width="20%">类型</td><td width="20%">收付类型</td><td width="20%">金额</td><td width="40%">备注</td></tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>车款</td>
                                            <td>收款</td>
                                            <td>
                                                <notempty name="first_payment_data">
                                                    <i class="receivables-money">{$first_payment_data.amount}</i>元
                                                    <else/>
                                                    <i class="receivables-money">0</i>元
                                                </notempty>
                                            <td>
                                                <textarea name="owner_remark_amount_of_car"></textarea>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>违约金</td>
                                            <td>收款</td>
                                            <td>
                                                <span><input type="text" value="" name="owner_payment_amount" class="paragraph"><label>元</label></span>
                                            </td>
                                            <td>
                                                <textarea name="owner_remark_payment"></textarea>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    <div class="receivable-money">应收车款：<span></span>元</div>
                                </div>

                                <div class="reasons-list" style="display: none;">
                                    <table>
                                        <thead>
                                        <tr><td width="20%">类型</td><td width="20%">收付类型</td><td width="20%">金额</td><td width="40%">备注</td></tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>应收车款</td>
                                            <td>收款</td>
                                            <td>
                                                <notempty name="first_payment_data">
                                                    <i class="receivables-money">{$first_payment_data.amount}</i>元
                                                    <else/>
                                                    <i class="receivables-money">0</i>元
                                                </notempty>
                                            </td>
                                            <td>
                                                <textarea name="normal_remark_amount_of_car"></textarea>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    <div class="receivable-money">应收车款：<span>{$first_payment_data.amount}</span>元</div>
                                </div>

                            </div>
                        </li>
                        <li>
                            <span>备注</span>
                            <textarea id="refund_remark_new" class="remarks_text"></textarea>
                        </li>
                    </ul>

                </div>
                <div class="yongBtn">
                    <input data-id="2" type="button" value="确定" class="queding self_refund">
                    <input type="button" onclick="history.back();" class="quxiao" value="返回">
                </div>
            </div>
            <div class="yuList"  style="display: none;">
                <div class="shop_details">
                    <ul>
                        <li>
                            <span>成交价</span>
                            <em><input id="trade_price" type="text" name="trade_price" value="" placeholder="请输入成交价"></em>
                        </li>
                        <li>
                            <span>交付服务费</span>
                            <em><input id="transfer_fee" type="text" name="transfer_fee" value=""
                                       placeholder="请输入交付服务费"></em>
                        </li>
                        <li>
                            <span>车商联系人</span>
                            <em><input id="dealer" type="text" name="dealer" value="" placeholder="请输入车商联系人"></em>
                        </li>
                        <li>
                            <span>联系人电话</span>
                            <em><input id="dealer_phone" type="text" name="dealer_phone" value="" placeholder="请输入车商电话"></em>
                        </li>
                        <li>
                            <span>提车人</span>
                            <em><input id="take_car_man" type="text" name="take_car_man" value="" placeholder="请输入提车人"></em>
                        </li>

                        <li>
                            <span>备注</span>
                            <textarea id="trade_remark" class="remarks_text"></textarea>
                        </li>
                    </ul>
                </div>
                <div class="yongBtn">
                    <input data-id="3" type="button" value="确定" class="queding self_other_deal">
                    <input type="button" onclick="history.back();" class="quxiao" value="返回">
                </div>
            </div>
        </div>
    </div>
    <div class="clear"></div>
</div>
<script>
    $(".menDao a").click(function () {
        $(".menDao a").removeClass("menHover");
        $(this).addClass("menHover");
        var back_method = $('#back_method').val();
        if (back_method == 1) {
            $('#buchang').show();
            $('#dakuan').show();
            $('#kouchu').hide();
        }else if(back_method == 2){
            $('#buchang').hide();
            $('#dakuan').hide();
            $('#kouchu').show();
        }
    });

    //初始化打款账户
    function initAccount(){
        var accountObj =  $('.reasons .playMoney table');
        var countAccount = accountObj.length;
        if (countAccount < 2) { //如果是一个账号时，让自动选中
            $('.reasons .playMoney table').addClass("accountCurrent");
            $("input[name='account_id']").val($(".account_id").html());
            $("input[name='bank_name']").val($(".bank_name").html());
            $("input[name='card_no']").val($(".card_no").html());
            $("input[name='account_name']").val($(".account_name").html());
        }
    }

    $(document).ready(function(){
        $("#reserve_time").ymdateplugin({
            showTimePanel: true,
            changeMonth: true,
            changeYear: true,
            gotoCurrent: true,
            ampm: true
        });

        $("#reserve_store").select2();

        $("#treatment a").eq(1).click(function(){
            $(".rechck_status").show();
        })
        $("#treatment a").eq(0).click(function(){
            $(".rechck_status").hide();
        })

        initAccount();

        $("#treatment1 a").click(function(){
            $("#treatment1 a").removeClass("menHover");
            $(this).addClass("menHover");
            var index=$("#treatment1 a").index(this);
            $(".reasons .reasons-list").eq(index).show().siblings().hide();
        })

        $(".paragraph").each(function(i){
            $(this).keyup(function(){
                var payment_reason = $("input[name='payment_reason']").val();
                $(this).val($(this).val().replace(/\D/g,''));
                var receivables=parseInt($(".receivables-money").eq(i).html());
                var first_payment_amount = '{$first_payment_data.amount}'; //首付款单
                var oInput=parseInt($(this).val());
                if(payment_reason == 2){ //如果是卖方违约,那么收款金额就是首付款单金额 + 赔付金额
                    if($(this).val()==""){
                        oInput = 0;
                    }
                    $(".receivable-money span").eq(i).html(Math.abs(first_payment_amount * 1 + oInput * 1));
                }else{

                    if($(this).val()==""){
                        oInput = 0;
                        $(".receivable-money").eq(i).find("span").html(first_payment_amount - oInput);
                    }
                    if((first_payment_amount - oInput) <0) {
                        $(".receivable-money span").eq(i).html(Math.abs(first_payment_amount - oInput));
                        $(".playMoney").show();
                        $(".receivable-money").eq(i).find("i").html("应付金额");
                    } else {
                        $(".receivable-money span").eq(i).html(Math.abs(first_payment_amount - oInput));
                        $(".playMoney").hide();
                        $(".receivable-money").eq(i).find("i").html("应收车款");

                    }
                }
            })
        })


        $("#back_method").val(2);
        //打款账号
        initAccount();

        $('.reasons .playMoney table').on('click', function () {
            $('.reasons .playMoney table').removeClass("accountCurrent");
            $(this).addClass("accountCurrent");

            $("input[name='account_id']").val($(this).find(".account_id").html());
            $("input[name='bank_name']").val($(this).find(".bank_name").html());
            $("input[name='card_no']").val($(this).find(".card_no").html());
            $("input[name='account_name']").val($(this).find(".account_name").html());
        });


        $(".driving_time").ymdateplugin({
            showTimePanel: true,
            changeMonth: true,
            changeYear: true
        });

        $(".transfer em").click(function () {
            $(".yuList ul .transfer em").removeClass("active");
            $("#transfer_limit").val($(this).attr('data-id'));
            $(this).addClass("active");
        })

        //self receive reauction
        $('.self_reauction').click(function(){

            var is_re_check = $('#is_re_check').val(); //是否重新检测
            if(is_re_check != 0){ // 如果选择了 重新检测，就要传递相应的预约时间和预约门店
                var reserve_time = $('#reserve_time').val(); //预约时间
                if(!reserve_time){
                    shibai_alert('请选择预约时间');
                    return;
                }
                var reserve_store = $('#reserve_store').val(); //预约门店
                if(reserve_store == 0){
                    shibai_alert('请选择门店');
                    return;
                }
            }
            var reserve_price = $("#reserve_price").val();
            if(reserve_price <= 0){
                shibai_alert("请输入正确的保留价");
                return;
            }
            var remark = $("#cp_remark").val();
            confirm_alert1('<div>请您确定重拍吗？<br/>' +
                    "保留价<span style='color:red;'>" + reserve_price + '元</span></div>',
                    self_reauction);
            function self_reauction() {
                $('.determine').click(function () {
                    colse_hide();
                    self_re_auction();
                });
            }
            function self_re_auction(){
                var post_data = {
                    'src_id' : "{$detail.src_id}",
                    'car_id' : "{$detail.car_id}",
                    'order_id' : "{$detail.order_id}",
                    'reserve_price': reserve_price,
                    'remark': remark
                };
                if(is_re_check != 0){
                    post_data.is_re_check = is_re_check; // 是否重新检测
                    post_data.reserve_time = reserve_time; // 预约时间
                    post_data.reserve_store = reserve_store; // 预约门店
                }
                _myPost('/SelfReceiveCar/self_receive_reauction',post_data);
            }
        });

        //self receive refund 自收车辆退车
        $('.self_refund').click(function(){
            var back_reason = $("input[name='payment_reason']").val();
            //postData.payment_reason = payment_reason;

            if(back_reason == 1 || back_reason == 2){ //平台违约或者卖方违约

                if(back_reason == 1){ //平台违约
                    var remark_payment = $("textarea[name='remark_payment']").val();
                    var remark_amount_of_car = $("textarea[name='remark_amount_of_car']").val();
                    var payment_amount = $("input[name='payment_amount']").val();
                }
                if(back_reason == 2){ //卖方违约
                    var remark_amount_of_car = $("textarea[name='owner_remark_amount_of_car']").val();
                    var remark_payment = $("textarea[name='owner_remark_payment']").val();
                    var payment_amount = $("input[name='owner_payment_amount']").val();
                }
                if(payment_amount < 0 || payment_amount == ''){
                    shibai_alert('输入金额不正确');
                    return;
                }
            }else{ //平退
                var remark_amount_of_car = $("textarea[name='normal_remark_amount_of_car']").val();
            }
            var car_source = "{$detail.car_source}";
            var pay_status = "{$detail.pay_status}";

            if (car_source == 1 ) {
                if(back_reason == 1){ //如果是平台失误，就要选择打款账号
                    //判断是否选中打款帐号
                    if (!$('.reasons .playMoney table').hasClass('accountCurrent')) {
                        shibai_alert('请选择打款账号');
                        return;
                    };
                    var account_id = $("#account_id_new").val();
                    var bank_name = $("#bank_name_new").val();
                    var card_no = $('#card_no_new').val();
                    var account_name = $("#account_name_new").val();
                }
            }
            var refund_remark = $("#refund_remark_new").val();
            //var compensate = payment_amount;
            if(refund_remark == ''){
                shibai_alert("请输入退车备注");
                return;
            }
            confirm_alert('<div>请您确定退车吗？</div>',
                    self_refund);
            function self_refund() {
                $('.determine').click(function () {
                    colse_hide();
                    self_re_refund();
                });
            }
            function self_re_refund(){
                var post_data = {
                    'src_id' : "{$detail.src_id}",
                    'car_id' : "{$detail.car_id}",
                    'order_id' : "{$detail.order_id}",
                    'back_reason':back_reason,//
                    //'compensate': compensate,
                    'back_method': '',
                    'account_id': account_id,
                    'bank_name': bank_name,
                    'card_no': card_no,
                    'account_name': account_name,
                    'refund_remark': refund_remark, //退车备注
                    'remark_amount_of_car':remark_amount_of_car, //车款备注
                    'remark_payment':remark_payment, //赔付备注
                    'payment_amount':payment_amount, //赔付金额

                };
                console.log(post_data);
                _myPost('/SelfReceiveCar/self_receive_refund',post_data);
            }
        });
        //self other channel deal
        $(".self_other_deal").click(function(){
            var trade_price = $("#trade_price").val();
            if(trade_price <= 0){
                shibai_alert("请输入正确的成交价");
                return;
            }

            var transfer_fee = $("#transfer_fee").val();
            if(transfer_fee < 0){
                shibai_alert("请输入正确的交付服务费");
                return;
            }
            var dealer = $("#dealer").val();
            if(dealer == ''){
                shibai_alert("请输入车商联系人");
                return;
            }
            var dealer_phone = $("#dealer_phone").val();
            if(dealer_phone == ''){
                shibai_alert("请输入联系人电话");
                return;
            }
            var take_car_man = $("#take_car_man").val();
            if(take_car_man == ''){
                shibai_alert("请输入提车人");
                return;
            }
            var trade_remark = $("#trade_remark").val();
            confirm_alert('<div>您确定此车以<br/>' + "<span style='color:red;'>"+trade_price +'元</span>成交吗？</div>',
                    self_other_deal);
            function self_other_deal() {
                $('.determine').click(function () {
                    colse_hide();
                    self_other_channel_deal();
                });
            }
            function self_other_channel_deal(){
                var post_data = {
                    'src_id' : "{$detail.src_id}",
                    'car_id' : "{$detail.car_id}",
                    'order_id' : "{$detail.order_id}",
                    'trade_price': trade_price,
                    'transfer_fee': transfer_fee,
                    'dealer': dealer,
                    'dealer_phone': dealer_phone,
                    'take_car_man': take_car_man,
                    'trade_remark': trade_remark
                };
                _myPost('/SelfReceiveCar/self_receive_other_channel_deal',post_data);
            }
        });
        function _myPost(url,PostData){
            $(".yunBei").css("display","block").unbind('click')
            $(".loading").fadeIn();
            $.post(url, PostData, function (data) {
                if(data.code != 200){
                    $(".loading").fadeOut();
                    $(".yunBei").css("display","none")
                    shibai_alert(data.msg);
                    return false;
                }
                btn_alert("操作成功", 2000, function () {
                    window.location.href = document.referrer;
                });
            }, 'json')
        }
    });
</script>
<include file="Public/foot" />